﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using com.pro2e.console.service.core;
using com.pro2e.web.util;
using System.Text;
using com.pro2e.web.config;
using sexhealth.console.service.post.vo;
using System.Collections.Generic;
using NHibernate.Criterion;

/// <summary>
/// Summary description for PostService
/// </summary>
namespace sexhealth.console.service.post
{
    public class PostService : ServiceImpl
    {
        SessionHelper sHelper = new SessionHelper();
        public PostService()
        {

        }



        public IList<ChannelVO> GetChannelList(int parentId)
        {
            DetachedCriteria dCriteria = DetachedCriteria.For(typeof(ChannelVO));
            dCriteria.Add(Expression.Eq("ParentId", parentId));
            dCriteria.AddOrder(Order.Asc("OrderNo"));
            return ExecutableDetachedCriteria<ChannelVO>(dCriteria);
        }

        public IList<PostVO> GetPostList(int chid)
        {
            DetachedCriteria dCriteria = DetachedCriteria.For(typeof(PostVO));
            dCriteria.Add(Expression.Eq("BelongToChannelId", chid));
            dCriteria.AddOrder(Order.Asc("OrderNo"));
            return ExecutableDetachedCriteria<PostVO>(dCriteria);
        }
        public IList<PostVO> GetPostList(int chid, int maxCount)
        {
            DetachedCriteria dCriteria = DetachedCriteria.For(typeof(PostVO));
            dCriteria.Add(Expression.Eq("BelongToChannelId", chid));
            dCriteria.AddOrder(Order.Desc("CreatedDate"));
            dCriteria.SetMaxResults(maxCount);
            return ExecutableDetachedCriteria<PostVO>(dCriteria);
        }
        public void InsertPost(PostVO post)
        {
            post.CreatedBy = sHelper.LoginUser.UserId;
            post.CreatedDate = DateTime.Now;
            DaoInsert(post);
        }
        public void UpdatePost(PostVO post)
        {
            post.UpdatedBy = sHelper.LoginUser.UserId;
            post.UpdatedDate = DateTime.Now;
            DaoUpdate(post);
        }

        public void InsertChannel(ChannelVO ch)
        {

            DaoInsert(ch);
        }

        public void UpdateChannel(ChannelVO ch)
        {
            DaoUpdate(ch);
        }

        
    }
}